//
//  CVCellOfTopic.m
//  LCOnePsychology
//
//  Created by li cheng on 16/9/12.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "CVCellOfTopic.h"
#import "BaseTableView.h"
#import "TVCellOfFirstTopic.h"
#import "MJMacro.h"
#import "RootClassOfHotTopic.h"
#import "DataOfHotTopic.h"
#import "CategoryOfDataHotTopic.h"
#import "UserOfDataHotTopic.h"
#import "BaseOfUserDataHotTopic.h"
#import "TeacherOfUserDataHotTopic.h"
#import "Way_Type_SetOfTeacherUserDataHotTopic.h"
#import "ZWYNetTool.h"
#import "UIImageView+WebCache.h"
@interface CVCellOfTopic()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) RootClassOfHotTopic *rootClassOfHotTopic;
@property (nonatomic, strong) BaseTableView *tableViewOfTopic;
@end
@implementation CVCellOfTopic
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        // 数据处理
        [self handleData];
    // 创建 TableView
        [self createTableView];
    }
    return self;
}
#pragma mark - 数据处理
- (void)handleData{
    [ZWYNetTool GET:@"http://yiapi.xinli001.com/v2/yi/teacher-topic-list.json?key=18ee0593a01c07f71d28fa936d671457&_platform=ios&_version=4.0&flag=hot" andBody:nil andHeader:nil andResponse:ZWYJSON andSuccessBlock:^(id result) {
        NSLog(@"%@", result);
        _rootClassOfHotTopic = [RootClassOfHotTopic modelDic:result];
        [self.tableViewOfTopic reloadData];
    } andFailureBlock:^(NSError *error) {
        
    }];
}
#pragma - mark 创建 TableView
- (void)createTableView{
    self.tableViewOfTopic = [[BaseTableView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.bounds.size.width, self.contentView.bounds.size.height) style:UITableViewStylePlain];
    [self.contentView addSubview:_tableViewOfTopic];
    self.tableViewOfTopic.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1.00];;
    self.tableViewOfTopic.delegate = self;
    self.tableViewOfTopic.dataSource = self;
    [self.tableViewOfTopic registerNib:[UINib nibWithNibName:@"TVCellOfFirstTopic" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"TVCellOfFirstTopic"];
    
}
#pragma mark - tableView 代理方法 row 数量的确定
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _rootClassOfHotTopic.data.count;
}
#pragma mark - tableView 代理方法 row 高度的确定
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return SCREEN_HEIGHT / 3;
}
#pragma mark - tableView 代理方法 cell 的赋值
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TVCellOfFirstTopic *cell = [tableView dequeueReusableCellWithIdentifier:@"TVCellOfFirstTopic" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1.00];

    [cell.coverImageView sd_setImageWithURL:[NSURL URLWithString:_rootClassOfHotTopic.data[indexPath.row].cover] placeholderImage:[UIImage imageNamed:@"0"]];
    cell.coverImageView.layer.cornerRadius = 10;
    cell.coverImageView.clipsToBounds = YES;
    [cell.avatarImageView sd_setImageWithURL:[NSURL URLWithString:_rootClassOfHotTopic.data[indexPath.row].user.avatar] placeholderImage:[UIImage imageNamed:@"0"]];
    cell.avatarImageView.layer.cornerRadius = 25;
    cell.avatarImageView.clipsToBounds = YES;
    cell.titleLabel.text = _rootClassOfHotTopic.data[indexPath.row].title;
    cell.nicknameLabel.text = _rootClassOfHotTopic.data[indexPath.row].user.nickname;
//    if (IS_IPHONE_5) {
//        [cell.nicknameLabel removeFromSuperview];
//    }
//    cell.nicknameLabel.frame =  CGRectMake(cell.nicknameLabel.frame.origin.x, cell.nicknameLabel.frame.origin.y, cell.nicknameLabel.frame.size.width - 20, cell.nicknameLabel.frame.size.height);
    
    cell.zixunnumLabel.text = [NSString stringWithFormat:@"%@人咨询过 ", _rootClassOfHotTopic.data[indexPath.row].user.teacher.zixunnum];
    cell.pricelabel.text = [NSString stringWithFormat:@"$%@人/次", _rootClassOfHotTopic.data[indexPath.row].price];
    return cell;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
